<!-- 项目列表 -->
<template>
  <div class="app-container development-container">
    <div class="development-content">
      <i class="el-icon-loading development-icon"></i>
      <h2 class="development-title">功能开发中</h2>
      <p class="development-desc">我们正在努力开发新功能，敬请期待...</p>
    </div>
  </div>
</template>

<script>
import {
  doQueryHisPage,
  doHisDelete
} from '@/api/xjs/work-order'
import { getNewDeptList } from '@/api/system/dept'
import ApplyDialog from '../history/components/applyDialog.vue'
import ReviewDialog from '../history/components/review.vue'
import EditDialog from '../history/components/editDialog.vue'
// 搜索
import { parseTime } from '@/utils'
import { projectClassList } from '@/utils/common'
export default {
  name: 'MyDraft',
  components: { ApplyDialog, ReviewDialog, EditDialog },
  data() {
    return {
      searchInfo: {
        name: '', // 项目名称
        applyDeptId: '', // 科室id
        openTime: '', // 准入时间
        applyUserName: '', // 申报人
        applyManagerName: '', // 责任人
        projectClass: '' // 项目分类
      },
      deptList: [], // 科室列表
      searchInfoCopy: null, // 用于重置
      pageInfo: {
        currentPage: 1,
        pageSize: 10,
        total: 0
      },
      projectClassList: projectClassList, // 项目分类列表
      parseTime: parseTime, // 时间处理
      timeValue: [],
      loading: false, // loading加载
      ticketList: [], // 列表数据
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      }
    }
  },
  computed: {},
  created() {
    this.searchInfoCopy = JSON.parse(JSON.stringify(this.searchInfo))
    this.getList()
    this.getDeptList()
  },
  methods: {
    // 新增
    onAdd() {
      // this.$refs.applyDialog.getNewDeptTreeList()
      this.$refs.applyDialog.open()
    },
    // 获取科室
    getDeptList() {
      getNewDeptList({ currentPage: 1, pageSize: 1000 }).then(res => {
        console.log(res)
        // const records = res.records[0]
        this.deptList = res.records
      })
    },
    // 搜索
    onSearch() {
      this.pageInfo.currentPage = 1
      this.getList()
    },
    // 重置
    resetQuery() {
      this.timeValue = []
      this.searchInfo = JSON.parse(JSON.stringify(this.searchInfoCopy))
      this.getList()
    },
    // 分页
    onPagination(obj) {
      this.pageInfo.currentPage = obj.page
      this.pageInfo.pageSize = obj.limit
      this.getList()
    },
    // 列表数据
    getList() {
      const params = {
        ...this.searchInfo,
        ...this.pageInfo
      }
      doQueryHisPage(params).then(res => {
        const data = res.records
        data.forEach(item => {
          const projectObj = this.projectClassList.find(it => it.value === item.projectClass)
          item.projectClassName = projectObj ? projectObj.label : ''
        })
        this.ticketList = data
        this.pageInfo.total = res.total
      })
    },
    // 表单数据弹窗
    handleView(row) {
      this.$refs.reviewDialog.open(row)
    },
    // 重新编辑提交弹窗
    handleEdit(row) {
      this.$refs.editDialog.open(row)
    },
    // 删除
    handleDelete(row) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          doHisDelete({ id: row.id }).then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getList()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    }
  }
}
</script>

<style lang="scss" scoped>
.development-container {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f5f7fa;
}

.development-content {
  text-align: center;
  padding: 40px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.development-icon {
  font-size: 48px;
  color: #409EFF;
  margin-bottom: 20px;
  animation: rotate 2s linear infinite;
}

.development-title {
  font-size: 24px;
  color: #303133;
  margin-bottom: 15px;
  font-weight: 500;
}

.development-desc {
  font-size: 16px;
  color: #909399;
  margin: 0;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
</style>
